<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/28/028
 * Time: 23:26
 */

namespace app\api\controller;

use think\Db;
use think\Request;
use think\controller;
use think\Session;

class Vip extends Rest
{

    public function index()
    {
        if (1 != self::check_power(3)) {
            return $this->data;
        }
    }

    public function addVipInfo()
    {

    }


    public function editVipInfo()
    {

    }

    public function delVipInfo()
    {

    }

    public function getVipInfo()
    {
        if (1 != self::check_power(1)) {
            return $this->data;
        }
        $request = Request::instance();
        $queryName = $request->post("queryName");
        $queryStudentId = $request->post("queryStudentId");
        $queryResult = Db::name("userinfo")->where(['Name'=>$queryName,'StudentId'=>$queryStudentId])->find();
        if($queryResult){
            $this->data['code'] = 1;
            $this->data['msg']  = '获取成功';
            $this->data['data'] = $queryResult;
        }else{
            $this->data['code'] = 0;
            $this->data['msg']  = '获取失败';
        }
        return $this->data;
    }


    public function getuserInfo()
    {
//        if (1 != self::check_power(1)) {
//            return $this->data;
//        }
        $studentId = Session::get("user");
        $queryResult = Db::name("userinfo")->where(["StudentID" => $studentId])->select();
        if($queryResult){
            foreach($queryResult as $key=>$value){
                $positionname = Db::name('position')->where(['position'=>$queryResult[$key]['Position']])->value("name");
                $queryResult[$key]['Position']  = $positionname;
                $departmentnameA = Db::name('department')->where(['type'=>$queryResult[$key]['PrimaryDepartmentA']])->value("name");
                $departmentnameS = Db::name('department')->where(['type'=>$queryResult[$key]['PrimaryDepartmentS']])->value("name");
                $queryResult[$key]['PrimaryDepartmentA'] = $departmentnameA;
                $queryResult[$key]['PrimaryDepartmentS'] = $departmentnameS;
                if($queryResult[$key]['Sex'] == 0){
                    $queryResult[$key]['Sex'] = "男";
                }else{
                    $queryResult[$key]['Sex'] = "女";
                }

            }
            $this->data['code'] = 1;
            $this->data['msg']  = '获取成功';
            $this->data['data'] = $queryResult;
        }else{
            $this->data['code'] = 0;
            $this->data['msg']  = '获取失败';
        }
        return $this->data;
    }

    public function authenticationVip(){
        if (1 != self::check_power(1)) {
            return $this->data;
        }
        $request = Request::instance();
        $queryName = $request->post("queryName");
        $queryStudentId = $request->post("queryStudentId");
        $queryResult = Db::name("userinfo")->where(['Name'=>$queryName,'StudentId'=>$queryStudentId,"Type"=>2])->find();
        if($queryResult){
            $this->data['code'] = 1;
            $this->data['msg']  = '本学生是协会会员';

        }else{
            $this->data['code'] = 0;
            $this->data['msg']  = '本学生暂不是协会会员';
        }
        return $this->data;
    }
}